<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId'.$cfgPack])
  || (isset($_SESSION['s_userType'.$cfgPack]) && isset($cfgFileNames['technician'][$_SESSION['s_userType'.$cfgPack]]) 
      && $cfgFileNames['technician'][$_SESSION['s_userType'.$cfgPack]] == 0))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	$itemDetailArray = array();
  $i               = 0;  
  
  $selectItem = "SELECT item.itemId,item.categoryId,item.subCategoryId,item.itemName,item.itemMake,item.modelNo,
  .                     item.currentStock,item.maxLevel,item.minLevel,category.categoryId,category.categoryName,
                        subcategory.subCategoryId,subcategory.subCategoryName
                   FROM item
                   JOIN category
                   JOIN subcategory
                  WHERE item.categoryId = category.categoryId
                    AND item.subCategoryId = subcategory.subCategoryId
                    AND status = 'A'";
  if(isset($_GET['categoryId'] ) && $_GET['categoryId'] > 0 )
  {
    $selectItem .= " AND item.categoryId = ".$_GET['categoryId'];               
  }
  if(isset($_GET['subCategoryId'] ) && $_GET['subCategoryId'] > 0 )
  {
    $selectItem .= " AND item.subCategoryId = ".$_GET['subCategoryId'];               
  }  
  if(isset($_GET['itemId'] ) && $_GET['itemId'] > 0 )
  {
    $selectItem .= " AND item.itemId = ".$_GET['itemId'];               
  }  
  $selectItem .= " ORDER BY itemName";
               
  $selectItemResult = mysql_query($selectItem);
  $itemRow = mysql_num_rows($selectItemResult);
  while($itemRow = mysql_fetch_array($selectItemResult))
  {
    $itemDetailArray[$i]['itemId']          = $itemRow['itemId'];
    $itemDetailArray[$i]['categoryName']    = $itemRow['categoryName'];
    $itemDetailArray[$i]['subCategoryName'] = $itemRow['subCategoryName'];
    $itemDetailArray[$i]['itemName']        = $itemRow['itemName'];
    $itemDetailArray[$i]['itemMake']        = $itemRow['itemMake'];
    $itemDetailArray[$i]['modelNo']         = $itemRow['modelNo'];
    $itemDetailArray[$i]['currentStock']    = $itemRow['currentStock'];
    $itemDetailArray[$i]['maxLevel']        = $itemRow['maxLevel'];
    $itemDetailArray[$i]['minLevel']        = $itemRow['minLevel'];
    $i++;     
  }
 
  include("./bottom.php");
  $smarty->assign("itemDetailArray",$itemDetailArray);
  $smarty->assign("i",$i);
  $smarty->display("productFilterAj.tpl");
}
?>